package org.unigram.oluolu.recommend;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;

/**
 *
 */
public class ExtractRecommendationMapper extends
        Mapper<LongWritable, Text, LongWritable, Text> {
    
    /**
     * map method.
     * 
     * @param key dummy
     * @param value value
     * @param context write key:userId value:candidate or features
     * 
     * @throws IOException -
     * @throws InterruptedException -
     */
    @Override
    public final void map(final LongWritable key,
            final Text value, final Context context)
            throws IOException, InterruptedException {

        String inputStr = value.toString();
        try {
            String[] tokens = inputStr.split("\t");
            context.write(new LongWritable(Long.parseLong(tokens[0])), 
                    new Text(tokens[2]));
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("PARSING ERROR in line: " + inputStr);
            e.printStackTrace();
        }
        
    }    

}
